<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<title>登录</title>
	<link rel="stylesheet" type="text/css" href="css/register-login.css">
	<script src="js/jquery-1.8.3.min.js" type="text/javascript"></script>
	<script src="js/common.js" type="text/javascript"></script>
</head>
<body>
<div id="box"></div>
<div class="cent-box">
	<div class="cent-box-header">
		<h2 class="sub-title">富宏堂中医馆</h2>
	</div>

	<div class="cont-main clearfix">
		<div class="index-tab">
			<div class="index-slide-nav">
				<a href="login.html" class="active">登录</a>
				<a href="register.html">注册</a>
				<div class="slide-bar"></div>				
			</div>
		</div>
		<div class="login form">
			<div class="group">
				<div class="group-ipt email">
					<input type="text" name="username" id="username" class="ipt" placeholder="输入用户名" required>
				</div>
				<div class="group-ipt user">
					<input type="password" name="password" id="password" class="ipt" placeholder="输入您的登录密码" required>
				</div>
			</div>
		</div>

		<div class="button">
			<button type="button" class="login-btn register-btn" id="button" style="background-color: #d9534f;">登录</button>
		</div>
		
	</div>
</div>
<script>
	$("#button").click(function(event){
		var userName = $("#username").val();
	    var password = $("#password").val();
	    if (userName == null || userName == "") {
	        alert('用户名不能为空！');
	        return;
	    }
	    if (password == null || password == "") {
	        alert('密码不能为空！');
	        return;
	    }
	    $.ajax({
	        type: "POST",
	        dataType: "json",
	        url: "/user/login",
	        data: {"username":userName,"password":password},
	        success: function (result) {
	            if (result.resultCode == 200) {
	                setCookie("username", result.data.username);
	                setCookie("userid", result.data.id);
	                window.location.href = "index.html";
	            }else {
	                alert('用户名或密码错误');
	            }
	        },
	        error: function () {
	            alert("异常！");
	        }
	    });
	})
</script>
</body>
</html>